{include file="public/layout" /}

<body style="background-color: #FFF; overflow: auto;min-width:auto;">
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page" style="min-width:auto;box-shadow:none;">
    <form class="form-horizontal" id="post_form" action="{:url('Index/ajax_add_welcome_tplfile')}" method="post">
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit">模板目录</dt>
                <dd class="opt" style="width: auto;">
                    {$tpldirpath}
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="url"><em>*</em>文件名称</label>
                </dt>
                <dd class="opt" style="width: auto;">
                    welcome_<input type="text" name="filename" value="{$filename}" id="filename" placeholder="请输入模板文件名" tabindex="2" onkeyup="this.value=this.value.replace(/[^\w\-]/g,'');" onpaste="this.value=this.value.replace(/[^\w\-]/g,'')" autocomplete="off">.htm
                    <span class="err"></span>
                    <p class="notic">只允许字母、数字、下划线、连接符的任意组合</p>
                    <p class="red" id="txt_filename"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="theme_title"><em>*</em>主题名称</label>
                </dt>
                <dd class="opt" style="width: auto;">
                    <input type="text" name="theme_title" placeholder="" id="theme_title" class="input-txt" autocomplete="off">
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <div class="bot">
                <input type="hidden" name="type" value="welcome">
                <a href="JavaScript:void(0);" onclick="checkForm();" class="ncap-btn-big ncap-btn-green" id="submitBtn" tabindex="4">确认提交</a>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
    $(function(){
        $('#filename').keyup(function(){
            $.ajax({
                type: "POST",
                url: "{:url('Ajax/new_appoint_tplfile', ['nosubmit'=>1,'_ajax'=>1])}",
                data: $('#post_form').serialize(),
                dataType: 'json',
                success: function (res) {
                    if(res.code == 1){
                        $('#txt_filename').html('');
                    } else {
                        $('#txt_filename').html(res.msg);
                    }
                }
            });
        });
    });

    // 判断输入框是否为空
    function checkForm(){
        if($('input[name=filename]').val() == ''){
            showErrorMsg('文件名称不能为空！');
            $('input[name=filename]').focus();
            return false;
        }
        if($('input[name=theme_title]').val() == ''){
            showErrorMsg('主题名称不能为空！');
            $('input[name=theme_title]').focus();
            return false;
        }
        layer_loading('正在处理');
        $.ajax({
            type: "POST",
            url: "{:url('Index/ajax_add_welcome_tplfile', ['_ajax'=>1])}",
            data: $('#post_form').serialize(),
            dataType: 'json',
            success: function (res) {
                if(res.code == 1){
                    var _parent = parent;
                    _parent.layer.closeAll();
                    $('#new_welcome_tplname', window.parent.document).before(res.data.html);
                    _parent.layer.msg(res.msg, {icon: 1, time: 1000});
                    return false;
                }else{
                    layer.closeAll();
                    if (res.data.focus) {
                        $('#'+res.data.focus).focus();
                    }
                    layer.msg(res.msg, {icon: 2});
                    return false;
                }
            },
            error:function(e){
                layer.closeAll();
                layer.alert(e.responseText, {icon: 2, title:false});
            }
        });
    }
</script>
{include file="public/footer" /}